<%@ tag import="com.biz.primus.base.tags.Layout" %>
<%@ tag import="java.util.Map" %>
<%@ tag import="java.util.Collection" %>
<%@taglib prefix="b" tagdir="/WEB-INF/tags/base" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%--标题--%>
<%@ attribute name="_title" required="true" type="java.lang.String" %>
<%--表单name--%>
<%@ attribute name="_name" required="true" type="java.lang.String" %>
<%--表单id--%>
<%@ attribute name="_id" required="false" type="java.lang.String" %>
<c:set var="_id" value="${empty _id ? _name : _id}"/>
<%--input占位符--%>
<%@ attribute name="_placeholder" required="false" type="java.lang.String" %>
<%--默认值--%>
<%@ attribute name="_value" required="false" type="java.lang.Object" %>
<%--是否必填项--%>
<%@ attribute name="_required" required="false" type="java.lang.Boolean" %>
<%--布局,可选single,twin,three三个值,对应单列,双列,三列--%>
<%@ attribute name="_layout" required="false" type="com.biz.primus.base.tags.Layout" %>
<c:set var="_layout" value="<%=_layout==null?Layout.single:_layout%>"/>
<%--input class,如果有则使用--%>
<%@ attribute name="_inputClass" required="false" type="java.lang.String" %>
<c:set var="_inputClass" value="${empty _inputClass? _layout.inputClass:_inputClass}"/>
<%--输入框列宽--%>
<%@ attribute name="_inputCol" required="false" type="java.lang.Integer" %>
<c:set var="_inputCol" value="${empty _inputCol? _layout.inputCol:_inputCol}"/>
<%--标题列宽--%>
<%@ attribute name="_titleCol" required="false" type="java.lang.Integer" %>
<c:set var="_titleCol" value="${empty _titleCol? _layout.titleCol:_titleCol}"/>

<%@attribute name="_items" type="java.lang.Object" required="true" %>
<%@attribute name="_valuePropertyName" type="java.lang.String" required="false" %>
<%@attribute name="_propertyName" type="java.lang.String" required="false" %>
<%--需要展示在首位的特殊值--%>
<%@attribute name="_specific" type="java.lang.Object" required="false" %>
<%--需要展示在首位的特殊值的value--%>
<%@attribute name="_specificValue" type="java.lang.Object" required="false" %>

<c:set var="_layout" value="<%=_layout==null?Layout.single:_layout%>" />

<b:row layout="${_layout}">
    <b:label title="${_title}" forId="${_id}" titleCol="${_titleCol}"/>
    <div class="col-sm-${_inputCol} radio form-group">
        <div class="col-xs-12">

        <c:if test="${not empty _specific}">
            <label>
                <input type="radio" name="${_name}" class="ace" value="${_specificValue}">
                <span class="lbl">${_specific}</span>
            </label>
        </c:if>
        <c:forEach items="${_items}" var="i" varStatus="index">
            <label>
            <c:choose>
                <c:when test="<%=_items instanceof Map%>">
                    <input type="radio" name="${_name}" class="ace" value="${i.key}" ${(empty _value and index.index eq 0 )or _value eq i.key?'checked':''}>
                    <span class="lbl">${i.value}</span>
                </c:when>
                <c:when test="<%=_items instanceof Collection%>">
                    <input type="radio" name="${_name}" class="ace" value="${i[_valuePropertyName]}" ${(empty _value and index.index eq 0 )or _value eq i[_valuePropertyName]?'checked':''}>
                    <span class="lbl">${i[_propertyName]}</span>
                </c:when>
                <c:otherwise>
                    items不是可迭代类型
                </c:otherwise>
            </c:choose>
            </label>
        </c:forEach>
        </div>
    </div>
</b:row>